home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9790 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: dawn.mmm.com!news
  2. From: kjhopps@mmm.com (Kevin J Hopps)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Mutexes make const functions impossible!?
  5. Date: 4 Mar 1996 14:57:01 GMT
  6. Organization: 3M - St. Paul, MN  55144-1000 US
  7. Message-ID: <4hf0bt$69q@dawn.mmm.com>
  8. References: <825596770.4813@redifon.demon.co.uk>
  9. Reply-To: kjhopps@mmm.com
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Guy Pickering (gp@redifon.demon.co.uk) wrote:
  13. > Usually, my classes have a number of const functions for getting internal
  14. > data (e.g. getWidth(), getNumEvents()). My problem is that when I wish
  15. > to be thread-safe, I need to lock and unlock a mutex every time I access
  16. > internal data. This means my functions can no longer be const because the
  17. > mutex member is being locked and unlocked.
  18.  
  19. > Is this a situation where the const'ness should be cast away, or am I
  20. > dammed to throw away all const'ness from thread-safe functions. Or is
  21. > there another solution?
  22.  
  23. You can make the mutex member mutable.  If your compiler does not support
  24. "mutable," this situation justifies casting away const.
  25. --
  26. Kevin J. Hopps                  e-mail: kjhopps@mmm.com
  27. 3M Company                      phone:  (612) 737-4643
  28. 3M Center, Bldg. 235-2D-57      fax:    (612) 737-2700
  29. St. Paul, MN 55144-1000         Opinions are my own.  I don't speak for 3M.
  30.     But 3M speaks for me -- I did not write the following line:
  31.  
  32. Opinions expressed herein are my own and may not represent those of 3M.
  33.